package com.vinfai.patterns.proxy.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
/**
 * jdk 动态代理：
 * 1、目标对象必须实现接口
 * 2、实现InvocationHandler.java 接口，处理
 * @author vinfai
 *
 */
public class JdkProxyTest {
	
	private static final Logger logger = LogManager.getLogger(JdkProxyTest.class);
	
	public  static void main(String[] args){
		SubjectInterface real = new RealSubject();
		InvocationHandler handler = new MyInvocationHandler(real);
		SubjectInterface test = (SubjectInterface)Proxy.newProxyInstance(JdkProxyTest.class.getClassLoader(), new Class[]{SubjectInterface.class}, handler);
		test.doSomething("参数1");
		test.doElse("参数2");
	}
	
	
	public void doTest(){
		logger.info("test....");
	}
	
}

